package com.winning.gjhlht.ihe.hl7ClientService.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.namespace.QName;

import net.sf.json.JSONObject;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.framework.helper.ServerSQLExecutorUtils;
import com.framework.util.date.DateConvert;
import com.winning.common.Constans;
import com.winning.common.data.dao.AppBaseDao;
import com.winning.common.data.service.PlatBasicDataService;
import com.winning.common.tools.XMLTool;
import com.winning.core.net.CXFWebserviceClent;

import chiss.org.draft.ihs.Expression;
import chiss.org.draft.ihs.FrequencyUse;
import chiss.org.draft.ihs.HealthStatistics;
import chiss.org.draft.ihs.HealthStatisticsAddress;
import chiss.org.draft.ihs.HealthStatisticsAuthenticator;
import chiss.org.draft.ihs.HealthStatisticsCustdian;
import chiss.org.draft.ihs.HealthStatisticsIndicator;
import chiss.org.draft.ihs.Identifier;
import chiss.org.draft.ihs.IndicatorData;
import chiss.org.draft.ihs.ProvideHealthStatisticsData;

@Controller
@RequestMapping("/testController")
public class TestController {
    private static Logger LOGGER = Logger.getLogger("pbsLoger");

    @RequestMapping(value = "/test/{paramName}", method = RequestMethod.GET)
    public @ResponseBody
    String getTestData(@PathVariable("paramName") String paramValue) {
        System.out.println("--> paramValue:" + paramValue);

        JSONObject modelMap = new JSONObject();
        modelMap.put("TESt", "1:" + paramValue);
        modelMap.put("success", "ererwerwerwerwerwerwerwerwe的发送到发送到");

        System.out.println("ererwerwerwerwerwerwerwerwe的发送到发送到," + paramValue);

        String resultStr = modelMap.toString();

        return resultStr;
    }


    public static void GRXXZCFH() {
        //根据本地模板来解析注册信息，跳过访问webservice注册个人信息步骤
        Document document = XMLTool.getXMLDocument("com/winning/ihe/hl7/patientPerson/persionRegistrationResult.xml");
        String responseXMLMessage = document.asXML();

        //PersionRegistrationServiceResponse ps = new PersionRegistrationServiceResponse();

        PlatBasicDataService platBasicDataService = new PlatBasicDataService();

        Map<String, Object> requestInfoMap = new HashMap<String, Object>();

        requestInfoMap.put("YLJGDM", "YLJGDM");
        requestInfoMap.put("GRJBXXBSH", "GRJBXXBSH");
        requestInfoMap.put("ZJHM", "ZJHM");
        requestInfoMap.put("ZJLXDM", "ZJLXDM");

//		ps.resonseHandler(platBasicDataService, responseXMLMessage, requestInfoMap);
    }

    /**
     * 方法名称: test
     *
     * @param
     * @return void 返回类型说明<br/>
     * @throws <br/>
     * @author lenovo@winning.com.cn<br/>
     * 创建时间：2016-12-30/上午2:37:10<br/>
     */
    public static void test() {
        String path = "com/winning/ihe/hl7/patientPerson/persionRegistration.xml";

        String wsdlURL = "http://59.255.59.31:8280/services/cbip?wsdl";

        Document doc = XMLTool.getXMLDocument(path);

        String message = doc.asXML();

        String xmlStr = message.substring(39, message.length());

        Object[] result = null;

        String responseXMLMessage = "";

        // 不依赖服务器端接口来完成调用的，也就是不仅仅能调用Java的接口
        JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
        Client client = clientFactory.createClient(wsdlURL);


        try {
            LOGGER.info("--> 调用开始:");

            result = client.invoke("HIPMessageServer", "PatientRegistryAddRequest", xmlStr);

            LOGGER.info("--> 调用结束:");
            if (result != null && result.length > 0) {

                responseXMLMessage = (String) result[0];

                System.out.println(responseXMLMessage);
            } else {
                System.out.println("--> cxf客户端调用返回结果为null");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    public static void main(String[] args) {

    }

}
